<?php

namespace app\controllers;
use Yii;
use yii\web\Controller;   //控制器基类

class TestController extends Controller
{
    public function behaviors(){
        return [
            'behavior'=>[
                'class'=>\app\components\MyBehavior::className(),
                'p1'=>'Hello PHP',
            ]
            
        ];
    }
   public function beforeAction($action) {  //执行方法之前执行,用于逻辑判断
       parent::beforeAction($action);
//       var_dump($action);
       echo $action->id;
       return parent::beforeAction($action);
   } 
//   public function afterAction(){
//       
//   } 
    
    public function actionIndex(){
//        echo  $this ->p1;
//        echo $this->getMethod();
        $model = new \app\models\Goods();
        echo $model->p1;
        echo $model->getMethod();
        return $this->renderPartial('index',['name'=>',zhangsan','age'=>22]);
    }
    
    public function actionSay($massage){
       echo $massage ;
    }
    
    public function actionThree(){
        
        //$request = new Request();
        var_dump(Yii::$app->request->get());
    }
    //返回数据的格式
    public  function actionDataformat(){
        Yii::$app->response->format= \yii\web\Response::FORMAT_JSON;   // = header('Content-type:application/json");
        return ['name'=>'张三','sex'=>'男'];
        
        
    }
    
    public function actionCache(){
        //存储缓存 默认是文件缓存
        Yii::$app->cache->set('name','张三',5);  //生成缓存 runtime/cache ,第三个参数为缓存有效期
        sleep(3);
        echo Yii::$app->cache->get('name');    //读取缓存
        
    }
    
    
    
    
    
}